let btn = document.getElementById('btn');
btn.addEventListener('click', clickHandler);

function clickHandler() {

}

setTimeout(() => {
    // some logics
}, 1000);

let xhr = new XMLHttpRequest();
xhr.open('get', 'data.json');
xhr.onreadystatechange = function () {

}
xhr.send();

const fs = require('fs');

fs.readFile('data.json', 'utf-8', (err, text) => {
    if (err) {
        // some logic
    } else {
        let data = JSON.parse(text);
    }
});

function ajax(method, url, params={}, token) {
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest();
        xhr.open(method, url);
        if (!token && localStorage.getItem('Authorization')) xhr.setRequestHeader("Authorization", localStorage.getItem('Authorization'));
        if (token) xhr.setRequestHeader("Authorization", token);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status <= 300 || xhr.status === 304) {
                    resolve(xhr.responseText);
                } else {
                    reject(xhr.responseText);
                }
            }
        }
        xhr.send(params);
    });
}
ajax('GET', 'xxxx/token')
.then(res => {
    localStorage.setItem('Authorization', res.token);
    return ajax('GET', 'xxxx/api/resouce1', {}, res.token);
})
.then(res => ajax('GET', 'xxxx/api/resouce2', {data: res.data}))
.then(res => ajax('GET', 'xxxx/api/resouce3', {data: res.data}))

p.then(val => {
    console.log("Do something on resolved value", val);
    // Do something
})